//
//  XJBaseVC.m
//  XJMCustomer
//
//  Created by Mr.hu on 2017/10/9.
//  Copyright © 2017年 Mr.hu. All rights reserved.
//

#import "XJBaseVC.h"

@interface XJBaseVC ()

@end

@implementation XJBaseVC

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
   
    //    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
//    [self.navigationController.navigationBar setTranslucent:NO];
//    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    //标题
//    NSDictionary * dict = @{NSForegroundColorAttributeName:RGBA(51, 51, 51, 1),NSFontAttributeName:[UIFont boldSystemFontOfSize:18]};
//    self.navigationController.navigationBar.titleTextAttributes = dict;
    //    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"bg_title"]forBarMetrics:UIBarMetricsDefault];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.edgesForExtendedLayout = UIRectEdgeAll;
    self.view.backgroundColor = [UIColor whiteColor];
    
    //导航
//    if(self.navigationController.viewControllers.count > 1){
//        [self addLeftBtn:[UIImage imageNamed:@"nav_back"] Action:@selector(backToPrevious)];
//    }
//    if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//        self.navigationController.interactivePopGestureRecognizer.delegate = nil;
//    }
//    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    //黑线
    
    //    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
    
    //    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    //    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
    //            switch (status) {
    //                case AFNetworkReachabilityStatusUnknown:
    //                    NSLog(@"未识别的网络");
    //                    break;
    //                case AFNetworkReachabilityStatusNotReachable:
    //                    [ToolClass showAlertTitle:@"提示" Message:@"网络无连接，请检查网络设置"];
    //                    break;
    //
    //                case AFNetworkReachabilityStatusReachableViaWWAN:
    //                    NSLog(@"2G,3G,4G...的网络");
    //                    break;
    //
    //                case AFNetworkReachabilityStatusReachableViaWiFi:
    //                    NSLog(@"wifi的网络");
    //                    break;
    //                default:
    //                    break;
    //            }
    //    }];
    //    [manager startMonitoring];
    // Do any additional setup after loading the view.
}

- (void)addLeftBtn:(UIImage *)image Action:(SEL)select
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 40, 40);
    [btn setImage:image forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [btn addTarget:self action:select forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    self.leftBtn = btn;
}
- (void)addLeftLabel:(NSString *)title Action:(SEL)select
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 40, 30);
    btn.titleLabel.font = [UIFont systemFontOfSize:16];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
    [btn addTarget:self action:select forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
}
- (void)addRightBtn:(UIImage *)image Action:(SEL)select
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 40, 40);
    [btn setImage:image forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    [btn addTarget:self action:select forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    self.rightBtn = btn;
}
- (void)addRightBtn:(UIImage *)image selectImg:(UIImage *)selectimage Action:(SEL)select{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 40, 40);
    [btn setImage:image forState:UIControlStateNormal];
    [btn setImage:selectimage forState:UIControlStateSelected];
    btn.titleLabel.font = [UIFont systemFontOfSize:14];
    [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    [btn addTarget:self action:select forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    self.rightBtn = btn;
}
- (void)addRightLabel:(NSString *)title Action:(SEL)select
{
    
    CGRect labelSize = [title boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:16]} context:nil];
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, labelSize.size.width+10, 30);
    btn.titleLabel.font = [UIFont systemFontOfSize:16];
    [btn setTitleColor:RGBA(213, 32, 30, 1) forState:UIControlStateNormal];
    [btn setTitle:title forState:UIControlStateNormal];
    [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    [btn addTarget:self action:select forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
}
- (void)backToPrevious
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)backToRootView
{
    [self.navigationController popToRootViewControllerAnimated:YES];
}

////支持设备自动旋转
//- (BOOL)shouldAutorotate
//{
//    return NO;
//}
////支持横竖屏显示
//- (UIInterfaceOrientationMask)supportedInterfaceOrientations
//{
//    return UIInterfaceOrientationMaskPortrait;
//}

////侧滑的问题
//- (void)viewDidAppear:(BOOL)animated {
//    [super viewDidAppear:animated];
//    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
//    }
//}
//
//- (void)viewDidDisappear:(BOOL)animated {
//    [super viewDidDisappear:animated];
//    //在其他离开改页面的方法同样加上下面代码
//    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
//        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
//    }
//}

@end
